import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description: 求2个整数的最大公约数
 * Author:  LiuTao
 * Version: 1.0
 * Date:    2023-04-16  22:03
 */
public class Test5 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        while(a != b){
            if(a > b){
                a -=b;
            }else{
                b -= a;
            }
        }
        System.out.println(a);
    }
}
